package com.zr.sms.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.sms.model.Goods;
import com.zr.sms.service.Goodsinfomanageservice;
import com.zr.sms.service.S_gAddService;
import com.zr.sms.serviceimpl.Goodsinfomanageserviceimpl;
import com.zr.sms.serviceimpl.S_gAddServiceImpl;



public class InsertgoodsServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		PrintWriter pw=resp.getWriter();
		HttpSession session=req.getSession();
		Goods gs=new Goods();
		String gname=req.getParameter("gname");
		String ginventory=req.getParameter("ginventory");
		String gprice=req.getParameter("gprice");
		String gdate=req.getParameter("gdate");
		String gquality=req.getParameter("gquality");
		String gaddress=req.getParameter("gaddress");
		String gclassify=req.getParameter("gclassify");
		String gcost=req.getParameter("gcost");
		int ginventory1=Integer.parseInt(ginventory);
		double  gprice1=Double.parseDouble(gprice);
		double gcost1 = Double.parseDouble(gcost);
		gs.setGname(gname);
		gs.setGinventory(ginventory1);
		gs.setGprice(gprice1);
		gs.setGdate(gdate);
		gs.setGquality(gquality);
		gs.setGaddress(gaddress);
		gs.setGclassify(gclassify);
		gs.setGcost(gcost1);
	    int sid=Integer.parseInt(req.getParameter("sid"));
	   
	    
		S_gAddService s_gAddService=new S_gAddServiceImpl();
		Goodsinfomanageservice gims=new Goodsinfomanageserviceimpl();
		boolean flag=gims.insertgoods(gs);
		int gid=gims.selectMaxGid();
	
		s_gAddService.adds_g(sid, gid);
		pw.write(String.valueOf(flag));
	}
}
